# -*- coding: utf-8 -*-
from dao.db import db

class StudyGroup(db.Model):
    __tablename__ = 'study_groups'

    id = db.Column(db.BigInteger, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    class_id = db.Column(db.BigInteger, db.ForeignKey('classes.id'), nullable=False)
    leader_id = db.Column(db.BigInteger, db.ForeignKey('students.id'), nullable=True)

    # 关系映射
    class_info = db.relationship('Class', backref='study_groups')
    leader_info = db.relationship('Student')

    __table_args__ = (
        db.UniqueConstraint('class_id', 'name', name='uk_class_group_name'),
        {'comment': '学习小组表'}
    )